<?php

class Ingenii_Log extends Ingenii_Core {
	
	private static $instance;
	
	private $logger;
	private $writer;
	
	public function __construct() {
		$settings = Ingenii_Config::getInstance()->base->logging;
		
		$path = $settings->directory.'/'.date('Y-m-d',time()).'.log';
		$stream = @fopen(BASEPATH . $path, 'a+', false);
		if (! $stream) {
		    throw new Exception('Failed to open stream');
		}
		$this->writer = new Zend_Log_Writer_Stream($stream);
		$this->logger = new Zend_Log($this->writer); 
	}
	
	public function __call($function, $arguments) {
		$this->logger->$function($arguments[0]);
	}
	
	public static function getInstance() {
        if (!Ingenii_Log::$instance instanceof self) {
            Ingenii_Log::$instance = new self();
        }
        return Ingenii_Log::$instance;
    }
	
}